<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="com.ejoysoft.etable.business.Magazine,
				 com.ejoysoft.common.Constants,
				 com.ejoysoft.util.ParamUtil,
				 com.ejoysoft.common.ApacheUpload,
				 java.io.File"%>
<%@ include file="../include/jsp/head.jsp"%>
<%
	Magazine obj=new Magazine(globa,false);
	ApacheUpload au = new ApacheUpload(request);
	action = au.getString(Constants.ACTION_TYPE);
    String strUrl="magazine_list.jsp";
	//上传文件
    String strFilePath = application.getRealPath("") + "/magazine/images/";
    File path = new File(strFilePath);
    if (!path.exists()) {
    	path.mkdirs();
    }
    String strSmallImage = "", strLargeImage = "", strFile = "";
    Magazine obj0 = null;
    if(action.equals(Constants.UPDATE_STR)){
		obj.setStrId(au.getString("strId"));
    	obj0 = obj.show(" where strId='" + obj.getStrId() + "'");
    }
    if (au.getFileName(0).length() > 0) {
    	strSmallImage = au.saveFile(strFilePath, 0);
    	if (action.equals(Constants.UPDATE_STR) && obj0.getStrSmallImage().length() > 0) {
    		File f = new File(strFilePath + obj0.getStrSmallImage());
    		f.delete();
    	}
    }
    if (au.getFileName(1).length() > 0) {
    	strLargeImage = au.saveFile(strFilePath, 1);
    	if (action.equals(Constants.UPDATE_STR) && obj0.getStrLargeImage().length() > 0) {
    		File f = new File(strFilePath + obj0.getStrLargeImage());
    		f.delete();
    	}
    }
    if (au.getFileName(2).length() > 0) {
    	strFile = au.saveFile(strFilePath, 2);
    	if (action.equals(Constants.UPDATE_STR) && obj0.getStrFile().length() > 0) {
    		File f = new File(strFilePath + obj0.getStrFile());
    		f.delete();
    	}
    }
    //赋值
    obj.setStrName(au.getString("strName"));
    obj.setStrSmallImage(strSmallImage);
    obj.setStrLargeImage(strLargeImage);
    obj.setStrFile(strFile);
    obj.setIntSort(au.getInt("intSort"));
    if(action.equals(Constants.ADD_STR)) {
	    globa.dispatch(obj.add(), strUrl);
	}else if(action.equals(Constants.UPDATE_STR)){
	    globa.dispatch(obj.update(obj.getStrId()),strUrl);
	}
    //关闭数据库连接对象
    globa.closeCon();
%>